package com.example.demo.service;

import com.example.demo.main.Collection;
import com.example.demo.main.CollectionExample;
import com.example.demo.mapper.CollectionMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UseSQLOfCollection {

    @Autowired
    private CollectionMapper collectionMapper;
    @Autowired
    private CollectionExample collectionExample;

    public List<Collection> selectByName(String name) {
        collectionExample.clear();
        collectionExample.or().andUserNameEqualTo(name);
        return collectionMapper.selectByExample(collectionExample);
    }

    public Integer insertByClass(Collection collection){
      return   collectionMapper.insertSelective(collection);
    }

    public List<Collection> selectByGoodsID(Long goodsID){
        collectionExample.clear();
        collectionExample.or().andGoodsIdEqualTo(goodsID);
        return collectionMapper.selectByExample(collectionExample);
    }
}
